<%@ Page language="c#" Inherits="Dimok.Aspx.Manager.Tracking.TrackingForm" CodeFile="TrackingForm.aspx.cs" %>
<%@ Register TagPrefix="Car" TagName="Info" Src="/Manager/Lib/Controls/CarInfo.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<TITLE id="title" runat="server" STYLE="behavior:url('#default#userData')">TrackingForm</TITLE>
<META name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"><META name="CODE_LANGUAGE" Content="C#"><META name="vs_defaultClientScript" content="JavaScript"><META name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<?XML:NAMESPACE PREFIX="COOL"/>
<?XML:NAMESPACE PREFIX="DIMOK"/>
<?IMPORT namespace="DIMOK" implementation="/include/htc/datagrid.htc">
<LINK rel="stylesheet" type="text/css" href="/CSS/Outlook.css">
<SCRIPT src="/include/common.js"></SCRIPT>
<SCRIPT src="/include/soap.js"></SCRIPT>
<SCRIPT src="/include/XML.js"></SCRIPT>
<SCRIPT src="/include/RDS.js"></SCRIPT>
<SCRIPT src="/include/Events.js"></SCRIPT>
<SCRIPT src="/Manager/Common/Events.js"></SCRIPT>
<STYLE>
cool\:tip{behavior: url(/Include/HTC/cooltip_js.htc)}
.cell {BORDER:1 black solid;background-color:white;width:100%;padding:1px}
CAPTION {BEHAVIOR: url(/Include/HTC/Toggle.htc);white-space:nowrap}
LEGEND {BEHAVIOR: url(/Include/HTC/Toggle.htc);white-space:nowrap}
</STYLE>
</HEAD>
<BODY onkeydown="showHist()" onload="load_Page()" id="ws">
<COOL:TIP id="oTip" avoidmouse="true" DURATION="30"></COOL:TIP>
<CAR:INFO />
<TABLE>
	<TR>
		<TD>Status</TD>
		<TD style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px" align="right">:</TD>
		<TD>
			<FIELDSET style="width:1%">
				<LEGEND state="+" PlusLast ontoggle="">
					<SELECT datasrc="#XmlLoanInfo" datafld="TrackerRequestStatusID" onchange="if(!confirm('Change status?'))return this.value=null;return UF_TF()" id="selRequestStatus" runat="server"></SELECT><INPUT type="button" value="Log" tabindex="-1" class="TipMe" coolTip="Co-o-o-ol1" onclick="TrackerRequest_History(this)" event="onclick"> <SPAN  style="VERTICAL-ALIGN: top">Notes:</SPAN> </LEGEND>
				<DIV nowrap style="display:none">
					<DIV>
						<TABLE datasrc="#XmlTrackerRequestNotes" border="1" cellpadding="0" cellspacing="0" style="BORDER-COLLAPSE: collapse">
							<THEAD>
								<TR>
									<TD colspan="10">
										<INPUT id="txtTrackerRequestNote" onupdate="TrackerRequest_Note(this)" style="width:100%;BEHAVIOR: URL(/include/HTC/BigList.htc); OVERFLOW-X: visible" xmlSrc="XmlTrackerRequestNotesList" textField="Note" loose>
									</TD>
								</TR>
								<TR><TH>Status</TH><TH>Note</TH><TH>When</TH><TH>Who</TH></TR>
							</THEAD>
							<TR>
								<TD><SPAN datafld="Status"></SPAN></TD>
								<TD><SPAN datafld="Note"></SPAN></TD>
								<TD><SPAN datafld="DateStamp"></SPAN></TD>
								<TD><SPAN datafld="UserName"></SPAN></TD>
							</TR>
						</TABLE>
					</DIV>
				</DIV>
			</FIELDSET>
		</TD>
	</TR>
	<TR valign="top">
		<TD>Installer</TD>
		<TD style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px" align="right">:</TD>
		<TD>
			<FIELDSET style="width:1%">
				<LEGEND state="+" PlusLast style="VERTICAL-ALIGN: middle" noTip>
					<SELECT datasrc="#XmlLoanInfo" datafld="TechnicianID" onchange="UF_TF(this);parentElement.state='-'" id="selTechnician" runat="server" NAME="selTechnician"></SELECT>
				</LEGEND>
				<DIV nowrap style="display:none">
				<DIV>Trackers :<INPUT type="button" value="Add" onclick="TrackerCar_Installed()"></DIV>
				<SELECT id="selTechTrackers" runat="server" size="5" multiple="true" title="Hold [Ctrl] key to select multiple trackers" NAME="selTechTrackers" tabindex="-1"></SELECT>
				</DIV>
			</FIELDSET>
			<TABLE datasrc="#XmlTechRating" style="BEHAVIOR: url(/Include/HTC/rowover_js.htc)"
						 SELECTABLE="1">
				<CAPTION align="left" state="+">Installer Ratings</CAPTION>
				<THEAD bgcolor="InactiveCaption" style="COLOR: captiontext" style="display:none">
					<TR><TH>Name</TH><TH>Distance</TH><TH>Pending</TH><TH>Total</TH></TR></THEAD>
				<TBODY style="display:none">
				<TR align="center">
					<TD align="right"><B><SPAN datafld="Name"></SPAN></B></TD>
					<TD><SPAN datafld="Distance"></SPAN></TD>
					<TD><SPAN datafld="Pending"></SPAN></TD>
					<TD><SPAN datafld="Total"></SPAN></TD>
				</TR>
				</TBODY>
			</TABLE>
		</TD>
	</TR>
</TABLE>
<XML id="XmlLoanInfo" Runat="server"></XML>
<XML id="XmlTrackerRequestNotes" Runat="server"></XML>
<XML id="XmlTrackerRequestNotesList" Runat="server"></XML>
<XML id="xmlRequests"><ASP:LITERAL ID="ltrRequests" Runat="server"></ASP:LITERAL></XML>
<DIV id="divRegHist" style="display:none">
<TABLE datasrc="#xmlReqHist" style="FONT: statusbar; BORDER-COLLAPSE: collapse" border="1" bordercolor="black" onreadystatechange="if(document.body.funcResize)document.body.funcResize()">
	<THEAD><TR><TH>When</TH><TH>Status</TH><TH>Installer</TH><TH>Who</TH></TR></THEAD>
	<TR>
		<TD nowrap><SPAN datafld="When"></SPAN></TD>
		<TD nowrap><SPAN datafld="Status"></SPAN></TD>
		<TD nowrap><SPAN datafld="Installer"></SPAN></TD>
		<TD nowrap><SPAN datafld="Who"></SPAN></TD>
	</TR>
</TABLE>
<XML id="xmlReqHist">[xml]</XML>
</DIV>
<XML runat="server" id="XmlTechRating"></XML>
</BODY>
</HTML>
<SCRIPT language="javascript">
initWS("Common","../Common/Common.asmx");
if( !this.frameElement )window.attachEvent("onresize",doResize);
title.load("WIN_WH");
var UF_TF = UF_AddCallBacks("UF_TF",changeRequestStatus,changeTechnician);
function doResize(ev){
	title.setAttribute("WIN_W",document.body.offsetWidth+8);
	title.setAttribute("WIN_H",document.body.offsetHeight+31);
	title.save("WIN_WH");
}
function load_Page(){
	attachToTrackerRequestStatus(document.location.reload,ApplID());
	//cropWindow();
	if( !this.frameElement )
		try{
			top.focus();
			resizeTo(title.getAttribute("WIN_W"),title.getAttribute("WIN_H"));
		}catch(e){}
}
function TrackerRequest_Note(el){
	var ret = WS(CO(),el.Text);
	if( showSOAPError(ret) )return;
	var rsTrackerRequestNotes = getRSFromDS(ret.value);
	if( !updateRS(XmlTrackerRequestNotes.recordset,rsTrackerRequestNotes ) )
		XmlTrackerRequestNotes.loadXML(ret.value);
	el.value = "";
}
function doUpdateVIN(el){
	var ret = WS(CO("TrackersByLoan"));
	if( showSOAPError(ret) )return;
	var rsTrackersNew = getRSFromDS(ret.value);
	if( !updateRS(_carInfo().rsTrackers,rsTrackersNew ) )
		_carInfo().xmlTrackers = getDSFromRS(rsTrackersNew).xml;
}
function changeRequestStatus(ret,el,fieldName,fieldValue,wsMethod){
	if( fieldName != "TrackerRequestStatusID" )return;
	WS(function(r){cb(r);},"TrackerRequest_Statuses");	
	//Locals
	function cb(ret){
	if( showSOAPError(ret) )return;
		refreshList();
		refreshAll(ret);
		//TechnicianTracker_InHands(selTechnician);
	}
}
function changeTechnician(ret,el,fieldName,fieldValue,wsMethod){
	if( fieldName != "TechnicianID" )return;
	TechnicianTracker_InHands(el);
}
function refreshList(){fireListRefresh({menuPath:"Tracking ->"});}
function refreshAll(ret){
	fillSelect(getRSFromDS(ret.value,"Statuses"),selRequestStatus,"MenuName","MenuID");
	var rsTrackersNew = getRSFromDS(ret.value,"Trackers");
	if( !updateRS(_carInfo().rsTrackers,rsTrackersNew ) )
		_carInfo().xmlTrackers = getDSFromRS(rsTrackersNew).xml;
	fillSelect(getRSFromDS(ret.value,"TechTrackers"),selTechTrackers,"TrackerID","TrackerID");
	updateRS(XmlLoanInfo.recordset,getRSFromDS(ret.value,"LoanInfo"));
}
function showTable(table){
	var b0 = table.tBodies[0];
	if( !b0 || table.readyState != "complete" )return;
	b0.style.display = isXmlRSEmpty(eval(table.dataSrc.substr(1)).recordset) ? "none" : "";
}
function TechnicianTracker_InHands(el){
	var ret = WS(CO(getFuncName()),el.value);
	if( showSOAPError(ret) )return;
	fillSelect(getRSFromDS(ret.value),selTechTrackers,"TrackerID","TrackerID");
	setTimeout(function(){document.body.focus()},100);
}
function TrackerCar_Installed(){
	if( !selTechTrackers.value )return alert("Select tracker(s).");
	if( !eval(selTechnician.value) )return alert("Select Installer.");
	var trackers = _trackerIDs(selTechTrackers);
	if( !confirm("Add tracker(s): "+trackers+"?") )return;
	var ret = WS(CO(),trackers);
	if( showSOAPError(ret) )return;
	refreshList();
	refreshAll(ret);
	//Locals
	function _trackerIDs(sel){
		for( var i=0,a=[]; i < sel.length; i++ )
			if( sel[i].selected )a.push(sel[i].value);
		return a;
	}
}
function TrackerRequest_History(el){
	var ret = WS(CO(getFuncName()));
	if( showSOAPError(ret) )return;
	el.coolTip = divRegHist.innerHTML.replace("[xml]",ret.value);
}
function showHist(columnName){//debugger;
	if( event.type == "keydown" && event.keyCode != 113 ){
		return;
	}
	columnName = columnName || document.activeElement.dataFld;
	if( !columnName )return alert("Select field first.");
	var ret = WS(CO("GetColumnHistory"),columnName);
	if( showSOAPError(ret) )return;
	grd.recordset = ret.value;
	grd.style.display = "";
}
function _carInfo(){return document.all.tags("CARINFO")[0];}
</SCRIPT>
